//
//  HDUITextField.swift
//  物料商行
//
//  Created by HaoDong Hong on 2017/8/12.
//  Copyright © 2017年 HaoDong Hong. All rights reserved.
//

import UIKit

class HDUITextField: UITextField {
    
    private var lineView = UIView()
    private var lineViewHeight: CGFloat = 0
    
    fileprivate func createLineView() {
        lineView.isUserInteractionEnabled = false
        configureLineHeight()
        lineView.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
        addSubview(lineView)
    }
    fileprivate func configureLineHeight() {
        let onePixel: CGFloat = 1.0 / UIScreen.main.scale
        lineViewHeight = onePixel * 4.0
        lineView.frame = CGRect(x: 0, y: bounds.size.height, width: bounds.size.width, height: lineViewHeight)
        lineView.backgroundColor = #colorLiteral(red: 0.5726983547, green: 0.565235734, blue: 0.09885739535, alpha: 1)
    }
    func animateLineView() {
        UIView.animate(withDuration: 0.3, animations: {
            self.lineView.frame.size.height = 0
        }) { (finished) in
            if finished {
                UIView.animate(withDuration: 0.15, animations: {
                    self.lineView.frame.size.height = self.lineViewHeight
                    self.lineView.backgroundColor = #colorLiteral(red: 0.1764705926, green: 0.4980392158, blue: 0.7568627596, alpha: 1)
                })
            }
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        createLineView()
    }
    
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        createLineView()
//        fatalError("init(coder:) has not been implemented")
    }
    
    
}
